import { Injectable, Optional, PipeTransform } from '@nestjs/common'
import { ParseFilePipe, ParseFilePipeOption } from '../parse-file/parse-file.pipe'

@Injectable()
export class ParseImageFilePipe
  extends ParseFilePipe<ParseImageFileOption>
  implements PipeTransform<Express.Multer.File, Express.Multer.File>
{
  /**
   * 默认的图片后缀名
   */
  static readonly EXTS = ['png', 'gif', 'jpg', 'jpeg', 'svg']

  constructor(@Optional() option?: ParseImageFileOption) {
    super({
      exts: ParseImageFilePipe.EXTS,
      ...option,
    })
  }
}

export interface ParseImageFileOption extends ParseFilePipeOption {}
